package com.zjmcollege.hotpot.repository;

import com.zjmcollege.hotpot.entity.Article;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * @author zpym
 * @CopyRight (C) http://www.zjmcollege.com
 * @brief
 * @email 122162005@qq.com
 * @date 2019-11-07 20:54
 */
@Repository
public interface ArticleRepository extends JpaRepository<Article, Long> {
    @Query(value = "SELECT * FROM articles WHERE MATCH(title, body) AGAINST" +
            "(?1 IN BOOLEAN MODE)", countQuery = "SELECT count(*) FROM articles " +
            "WHERE MATCH(title, body) AGAINST(?1 IN BOOLEAN MODE)",
            nativeQuery = true)
    Page<Article> findByKey(String key, Pageable pageable);
}
